package com.stu.covid.business.controller;

import com.stu.covid.business.entity.Clazz;
import com.stu.covid.business.entity.Teacher;
import com.stu.covid.business.service.ClazzService;
import com.stu.covid.business.service.TeacherService;
import com.stu.covid.business.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@Slf4j
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @GetMapping("/to-clazz-list")
    public String toClazzList() {
        return "clazz_list";
    }

    @GetMapping("/to-clazz-add")
    public String toClazzAdd() {
        return "clazz_add";
    }

    @RequestMapping("/clazz-list")
    @ResponseBody
    public Result<Clazz> clazzList(Clazz clazz) {
        return clazzService.clazzList(clazz);
    }

    @RequestMapping("/clazz-add")
    public String clazzAdd(Clazz clazz) {
        clazzService.clazzAdd(clazz);
        return "redirect:to-clazz-list";
    }


    @RequestMapping("/clazz-del")
    public String clazzDel(Clazz clazz) {
        clazzService.clazzDel(clazz.getId());
        return "redirect:to-clazz-list";
    }
}
